package com.ruoyi.pms.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.pms.domain.PmsRequestDetails;
import com.ruoyi.pms.service.IPmsRequestDetailsService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 采购申请Controller
 * 
 * @author ruoyi
 * @date 2021-11-04
 */
@RestController
@RequestMapping("/requestDetails")
public class PmsRequestDetailsController extends BaseController
{
    @Autowired
    private IPmsRequestDetailsService pmsRequestDetailsService;

    /**
     * 查询采购申请列表
     */
    @PreAuthorize(hasPermi = "pms:requestDetails:listDetail")
    @GetMapping("/list")
    public TableDataInfo list(PmsRequestDetails pmsRequestDetails)
    {
        startPage();
        List<PmsRequestDetails> list = pmsRequestDetailsService.selectPmsRequestDetailsList(pmsRequestDetails);
        return getDataTable(list);
    }

    /**
     * 查询采购申请列表
     */
    @PreAuthorize(hasPermi = "pms:requestDetails:list")
    @GetMapping("/listDetail")
    public TableDataInfo listRequestDetail(PmsRequestDetails pmsRequestDetails)
    {
        startPage();
        List<PmsRequestDetails> list = pmsRequestDetailsService.listRequestDetail(pmsRequestDetails);
        return getDataTable(list);
    }

    /**
     * 导出采购申请列表
     */
    @PreAuthorize(hasPermi = "pms:requestDetails:export")
    @Log(title = "采购申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PmsRequestDetails pmsRequestDetails) throws IOException
    {
        List<PmsRequestDetails> list = pmsRequestDetailsService.selectPmsRequestDetailsList(pmsRequestDetails);
        ExcelUtil<PmsRequestDetails> util = new ExcelUtil<PmsRequestDetails>(PmsRequestDetails.class);
        util.exportExcel(response, list, "采购申请数据");
    }

    /**
     * 获取采购申请详细信息
     */
    @PreAuthorize(hasPermi = "pms:requestDetails:query")
    @GetMapping(value = "/{requestDetailUuid}")
    public AjaxResult getInfo(@PathVariable("requestDetailUuid") String requestDetailUuid)
    {
        return AjaxResult.success(pmsRequestDetailsService.selectPmsRequestDetailsByRequestDetailUuid(requestDetailUuid));
    }

    /**
     * 新增采购申请
     */
    @PreAuthorize(hasPermi = "pms:requestDetails:add")
    @Log(title = "采购申请", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PmsRequestDetails pmsRequestDetails)
    {
        return toAjax(pmsRequestDetailsService.insertPmsRequestDetails(pmsRequestDetails));
    }

    /**
     * 修改采购申请
     */
    @PreAuthorize(hasPermi = "pms:requestDetails:edit")
    @Log(title = "采购申请", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PmsRequestDetails pmsRequestDetails)
    {
        return toAjax(pmsRequestDetailsService.updatePmsRequestDetails(pmsRequestDetails));
    }

    /**
     * 删除采购申请
     */
    @PreAuthorize(hasPermi = "pms:requestDetails:remove")
    @Log(title = "采购申请", businessType = BusinessType.DELETE)
	@DeleteMapping("/{requestDetailUuids}")
    public AjaxResult remove(@PathVariable String[] requestDetailUuids)
    {
        return toAjax(pmsRequestDetailsService.deletePmsRequestDetailsByRequestDetailUuids(requestDetailUuids));
    }
}
